package com.littlepay.kr4.paulin.dfeba77;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.hanks.passcodeview.PasscodeView;
import com.littlepay.kr4.paulin.dfeba77.utils.PrefUtils;

public class LockSettingActivity extends AppCompatActivity {
    //首先是未验证，才去验证密码
    public static boolean isVerify = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lock_setting);
//        try {
//            Intent intent0 = this.getIntent();
//            isVerify = (boolean) intent0.getSerializableExtra("isVerify");
//        }catch (Exception e){
//            e.printStackTrace();
//        }

        //TODO:设置密码以后再点击隐私，应该怎么处理？
        if(PrefUtils.getLocked() && !isVerify){
            //锁定状态需要进入验证，需要携带信息，说明我是从设置进来的！
            Intent intent = new Intent(this,LockActivity.class);
            Bundle bundle = new Bundle();
            bundle.putSerializable("isLogin",false);
            intent.putExtras(bundle);
            startActivity(intent);
            Toast.makeText(getApplication(),"修改密码需要验证先前设置的密码",Toast.LENGTH_SHORT).show();
        }else {
            final PasscodeView passcodeView_setting = (PasscodeView) findViewById(R.id.passcodeView_setting);
            passcodeView_setting
                    .setListener(new PasscodeView.PasscodeViewListener() {
                        @Override
                        public void onFail() {
                            Toast.makeText(getApplication(),"两次密码不一致",Toast.LENGTH_SHORT).show();
                        }

                        @Override
                        public void onSuccess(String number) {
                            Toast.makeText(getApplication(),"您的密码是: "+ number +", 请记牢和妥善保管",Toast.LENGTH_SHORT).show();
                            PrefUtils.setPassword(number);
                            PrefUtils.setLocked(true);
                            finish();
                        }
                    });
        }

    }
}
